const path = require('path');
const htmlWebpackPlugin = require('html-webpack-plugin');
const vueLoaderPlugin = require('vue-loader/lib/plugin');
const webpack = require('webpack');

module.exports = {
    entry: './src/main.js',
    output: {
      filename: '[name].[chunkhash:8].bundle.js',
      path: path.join(__dirname, 'dist')
    },
    module: {
      rules: [
          {
            test: /\.js$/,
            use: {
                loader: 'babel-loader',
                options: {
                    presets: ['@babel/preset-env']
                }
            }
          },
          {
              test: /\.(js|vue)$/,
              use: 'eslint-loader',
              enforce: 'pre',
              exclude: '/node_modules/'
          },
          {
            test: /\.png$/,
            use: {
                loader: 'file-loader',
                options: {
                    esModule: false,
                    outputPath: 'assets'
                }
            }
          },
          {
              test: /\.(less|css)$/,
              use: ['style-loader','css-loader','less-loader']
          },
          {
              test: /\.vue$/,
              loader: 'vue-loader'
          }
      ]
    },
    plugins: [
        new htmlWebpackPlugin({
            title: 'webpack 构建 vue',
            template: './src/index.html',
            cache: false
        }),
        new vueLoaderPlugin(),
        new webpack.DefinePlugin({
            BASE_URL: JSON.stringify('public/')
        })
    ]
};
